package com.feicheng.controller.system;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.common.sms.SmsUtils;
import com.feicheng.service.IFLoginService;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import jakarta.servlet.http.HttpSession;
import java.util.Map;

@RestController("/admin/system/login")
@RequestMapping("/admin/system/login")
public class LoginController {

    @Autowired
    HttpSession session;

    @Resource(name="main-system-login")
    Map<String, IFLoginService> systemLoginService;

    @PutMapping("/ap")
    public ResultInfo login(@RequestBody JSONObject param) {
        return systemLoginService.get(Constant.LOGIN_TYPE.AP).login(param.toJSONString());
    }

    @GetMapping("/tm")
    public ResultInfo login(String tel, String code) {
        JSONObject param = new JSONObject();
        return systemLoginService.get(Constant.LOGIN_TYPE.TM).login(param.toJSONString());
    }

    @Autowired
    SmsUtils smsUtils;

    @GetMapping("/sm")
    public ResultInfo sm() throws TencentCloudSDKException {
        JSONArray phoneNumbers = new JSONArray();

        phoneNumbers.add("18341167862");

        smsUtils.sendMessage(phoneNumbers, "1234");
        return ResultInfo.success();
    }

}
